#include "delay.h"

void delay(int time)
{
    int i, j;
    for (i = 0; i < time; i++)
    {
        for (j = 0; j < 0x413c; j++)
            ;
    }
}

void delay_us(uint32_t time)
{
    SysTick->CTRL = 0;
    SysTick->LOAD = time * 21 - 1;
    SysTick->VAL = 0;
    SysTick->CTRL = 0x01;
    while ((SysTick->CTRL & (1 << 16)) == 0)
        ;
    SysTick->CTRL = 0;
}

void delay_ms(uint32_t time)
{
    while(time--)
    {
        delay_us(1000);
    }
}

void delay_ms_led(uint32_t time)
{
    while (time--)
    {
        delay_us(1000);
        if (GPIO_ReadInputDataBit(KEY_GROUP, KEY1_PIN) == 0)
        {
            break;
        }
    }
}

void delay_s(uint32_t time)
{
    while (time--)
    {
        delay_ms(1000);
    }
}
